package diona.components

import org.joda.time.format.DateTimeFormat
import org.joda.time.LocalDate
import net.liftweb.util.BindHelpers
import java.util.{Calendar, Locale}

/**
 * User: anton
 * Date: 23.07.11 21:19
 */
trait SnippetsUtil extends BindHelpers {

  val dateTimeFormatter = DateTimeFormat.forPattern("dd-MMMM-yyyy HH:mm:ss").withLocale(new Locale("ru", "ru"))
  val dateFormatter = DateTimeFormat.forPattern("dd-MMMM-yyyy").withLocale(new Locale("ru", "ru"))

  def formatDate(date: Option[LocalDate]): String = {
    date.map(dateFormatter.print(_)).getOrElse("")
  }

  def formatDate(date: Calendar): String = dateTimeFormatter.print(date.getTimeInMillis)
}